package Messages;

import Agents.Messageable;
import Agents.OfficeRegion;
import Agents.VacuumCleaner;
import Messages.AMessage.MessageType;
import Messages.AMessage.Units;

public class VacuumCleanerMessage extends AMessage
{
	public VacuumStatus status;
	public int timeToUse;
	public int dirtyPct;
	public MessageType theType;
	
	protected String constructSpecialMessage(Messageable agent)
	{
		return ((VacuumCleaner)agent).getLocalName() + AMessage.senderSplit + Units.VACUUM_CLEANER.name() + AMessage.unitSplit + ((VacuumCleaner)agent).status.name();
	}

	protected String constructSpecialMessage(Messageable agent, MessageType type)
	{
		if (type == AMessage.MessageType.CALL_CLEAN)
			return ((OfficeRegion)agent).getLocalName() + AMessage.senderSplit + Units.FLOOR_PCT_DIRTY.name() + AMessage.unitSplit + ((OfficeRegion)agent).pctDirty;
		if (type == AMessage.MessageType.PROPOSE_CLEAN)
			return ((VacuumCleaner)agent).getLocalName() + AMessage.senderSplit + Units.VACUUM_CLEANER_TIMETOUSE.name() + AMessage.unitSplit + ((VacuumCleaner)agent).timeToUseOnTask;
		if (type == AMessage.MessageType.PROPOSE_EMPTY_BIN)
			return ((VacuumCleaner)agent).getLocalName() + AMessage.senderSplit + Units.VACUUM_CLEANER_TIMETOUSE.name() + AMessage.unitSplit + ((VacuumCleaner)agent).timeToUseOnTask;
		return null;
	}

	protected void retrieveMyMessage(String theMessage)
	{
		try
		{
			String[] send = theMessage.split(AMessage.senderSplit);
			sender = send[0];
			String[] information = send[1].split(AMessage.unitSplit);
			switch (this.getMessageType())
			{
				case CALL_CLEAN:
					dirtyPct = Integer.parseInt(information[1]);
					break;
				case PROPOSE_CLEAN:
					timeToUse = Integer.parseInt(information[1]);
					break;
				case PROPOSE_EMPTY_BIN:
					timeToUse = Integer.parseInt(information[1]);
					break;
				default:
					if (AMessage.VacuumStatus.CHARGING.name().equalsIgnoreCase(information[1]))
						status = AMessage.VacuumStatus.CHARGING;
					else if (AMessage.VacuumStatus.NEED_POWER.name().equalsIgnoreCase(information[1]))
						status = AMessage.VacuumStatus.NEED_POWER;
					else if (AMessage.VacuumStatus.VACUUMING.name().equalsIgnoreCase(information[1]))
						status = AMessage.VacuumStatus.VACUUMING;
					else if (AMessage.VacuumStatus.IDLE.name().equalsIgnoreCase(information[1]))
						status = AMessage.VacuumStatus.IDLE;
			}
		}
		catch (Exception e)
		{
			System.out.println(theMessage);
		}
	}
}
